"""
 -*- coding: utf-8-*-
 @File: page_add_pet.py
 @Author: chen
 @time: 2024/01/10/ 20:32
"""
import time

from ui_test.page_po_test.page_business.page_base import BasePage
from ui_test.page_po_test.page_business.page_home import HomePage


class AddPetPage(BasePage):
    def input_pet_name(self, pet_name):
        text_pet_name = (self.by.NAME, "name")
        self.logger.info(f"输入宠物名字：{pet_name}")
        self.do_input(text_pet_name, pet_name)
        return self

    def input_birth_date(self, pet_birth):
        text_birth_date = (self.by.XPATH, '//*[@ng-reflect-name="birthDate"]')
        self.logger.info(f"输入宠物出生日期：{pet_birth}")
        self.do_input(text_birth_date, pet_birth)
        return self

    def select_pet_type(self, pet_type):
        select_box = (self.by.NAME, "type")
        self.logger.info("点击类型选择框")
        self.do_click(select_box)
        choose_pet_type = (self.by.XPATH, f'//*[text()="{pet_type} "]')
        self.logger.info(f"选择宠物类型：{pet_type}")
        self.do_click(choose_pet_type)
        return self

    def back_to_pet_mgt_page(self):
        btn_back = (self.by.XPATH, '//*[text()="< Back"]')
        self.logger.info("点击返回按钮")
        self.do_click(btn_back)
        from ui_test.page_po_test.page_business.page_pet_mgt import PetMgtPage
        self.logger.info("回到宠物主人信息页面")
        return PetMgtPage(self.driver)

    def click_save_pet(self):
        btn_save_pet = (self.by.XPATH, '//*[text()="Save Pet"]')
        self.logger.info("点击保存宠物按钮")
        self.do_click(btn_save_pet)
        return self

    def add_to_pet_mgt_page(self, pet_name, pet_birth, pet_type):
        self.input_pet_name(pet_name). \
            input_birth_date(pet_birth). \
            select_pet_type(pet_type). \
            click_save_pet()
        from ui_test.page_po_test.page_business.page_pet_mgt import PetMgtPage
        self.logger.info("回到宠物主人信息页面")
        return PetMgtPage(self.driver)


if __name__ == '__main__':
    cur_page = HomePage().goto_owner_mgt_page().goto_pet_mgt_page("murong", "shaozong").goto_add_pet_page()
    cur_page.add_to_pet_mgt_page("xiaoqiang", "20240101", "cat")
    time.sleep(5)
